package com.iotproject.blogservice.controller;


import com.iotproject.blogservice.entity.BlogType;
import com.iotproject.blogservice.service.BlogTypeService;
import com.iotproject.commonutils.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 博客类型 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2023-03-29
 */
@RestController
@RequestMapping("/blogservice/blog-type")
public class BlogTypeController {

    @Autowired
    BlogTypeService blogTypeService;

    //插入博客类别
    @GetMapping("insertBlogType")
    public R insertBlogType() {
        BlogType blogType1 = new BlogType();
        blogType1.setTitle("幼儿英语");
        blogType1.setSort(0);
        boolean save = blogTypeService.save(blogType1);
        if (save) {
            return R.ok();
        } else {
            return R.error();
        }
    }

    //查询博客类别列表
    @GetMapping("blogTypeList")
    public R getBlogTypeList() {
        QueryWrapper<BlogType> blogTypeQueryWrapper = new QueryWrapper<>();
        blogTypeQueryWrapper.orderByAsc("sort");
        List<BlogType> list = blogTypeService.list(blogTypeQueryWrapper);
        return R.ok().data("items", list);
    }



}

